{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"https://raw.githubusercontent.com/Qiskit/qiskit-tutorials/master/images/qiskit-heading.png\" alt=\"Note: In order for images to show up in this jupyter notebook you need to select File => Trusted Notebook\" width=\"500 px\" align=\"left\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## _*Single-qubit Quantum Random Access Coding (QRAC)*_ \n",
    "\n",
    "The latest version of this notebook is available on https://github.com/QISKit/qiskit-tutorial.\n",
    "\n",
    "***\n",
    "### Contributors\n",
    "Rudy Raymond, Takashi Imamichi\n",
    "\n",
    "### Qiskit Package Versions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'qiskit': '0.10.3',\n",
       " 'qiskit-terra': '0.8.1',\n",
       " 'qiskit-ignis': '0.1.1',\n",
       " 'qiskit-aer': '0.2.1',\n",
       " 'qiskit-ibmq-provider': '0.2.2',\n",
       " 'qiskit-aqua': '0.5.1'}"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import qiskit\n",
    "qiskit.__qiskit_version__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Introduction\n",
    "\n",
    "Random Access Coding (RAC) is one of few examples where a small number of quantum bits can exhibit properties that cannot be achieved by the same amount of classical bits. To demonstrate the power of Quantum RAC with a single qubit, consider a case where the sender, say, Alice, wants to encode $n$ bits of information into a qubit. The qubit is then sent to the receiver, say, Bob, who will decode it to obtain one bit (out of $n$ bits sent by Alice) of his choice (which is unknown to Alice). It is known that there is no way for Alice to encode her $2$ bits into one classical bit so that Bob can then recover any bit with success probability better than half. \n",
    "\n",
    "On the other hand, with a single qubit it is possible to encode up to $3$ bits of information such that the receiver is quaranteed to observe his choice of bit with probability better than random guessing. The encoding and decoding scheme for encoding 2 bits and 3 bits of information into 1 qubit are denoted as, respectively, $(2,1)$-QRAC and $(3,1)$-QRAC.   \n",
    "\n",
    "Here, using `QuantumProgram` of IBM Q Experience we describe how to construct the $(2,1)$-QRAC, i.e., encoding $2$ bits of information into $1$ qubit so that any bit can be recovered with probability at least $0.85$, as well as the $(3,1)$-QRAC, i.e., encoding $3$-bits of information into $1$ qubit so that any bit can be recovered with probability at least $0.78$. All necessary unitary gates and measurements can be realized by the $u3$ rotation gates included in the [qelib1.inc](https://github.com/IBM/qiskit-openqasm/blob/master/examples/generic/qelib1.inc) whose mathematical definition can be found [here](https://github.com/IBM/qiskit-openqasm/blob/master/spec/qasm2.pdf).\n",
    "\n",
    "First, we prepare the environment."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# useful math functions\n",
    "from math import pi\n",
    "\n",
    "# importing QISKit\n",
    "from qiskit import Aer, IBMQ\n",
    "from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute\n",
    "from qiskit.tools.visualization import plot_histogram\n",
    "from qiskit.tools.monitor import job_monitor\n",
    "from qiskit.providers.ibmq import least_busy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "IBMQ.load_accounts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Encoding 2 bits into 1 qubit with $(2,1)$-QRAC\n",
    "We follow Example 1 described in the paper [here](http://iopscience.iop.org/article/10.1088/1367-2630/8/8/129/meta). Alice encodes her $2$ bits $x_1x_2$ by preparing the following 1-qubit states $|\\phi_{x_1x_2}\\rangle$.\n",
    "\n",
    "\\begin{eqnarray}\n",
    "|\\phi_{00}\\rangle &=& \\cos\\left(\\pi/8\\right)|0\\rangle + \\sin\\left(\\pi/8\\right)|1\\rangle\\\\\n",
    "|\\phi_{10}\\rangle &=& \\cos\\left(3\\pi/8\\right)|0\\rangle + \\sin\\left(3\\pi/8\\right)|1\\rangle\\\\\n",
    "|\\phi_{11}\\rangle &=& \\cos\\left(5\\pi/8\\right)|0\\rangle + \\sin\\left(5\\pi/8\\right)|1\\rangle\\\\\n",
    "|\\phi_{01}\\rangle &=& \\cos\\left(7\\pi/8\\right)|0\\rangle + \\sin\\left(7\\pi/8\\right)|1\\rangle\\\\\n",
    "\\end{eqnarray}\n",
    "\n",
    "Bob recovers his choice of bit by measuring the qubit in the following way. If he wants to recover the first bit (i.e., $x_1$), he measures the qubit in the $\\left\\{|0\\rangle, |1\\rangle\\right\\}$ basis, namely, he concludes $0$ if he observes $|0\\rangle$, and $1$ otherwise. On the other hand, if he wants to recover the second bit (i.e., $x_2$), he measures the qubit in the $\\left\\{|+\\rangle, |-\\rangle\\right\\}$ basis, where $|+\\rangle = 1/\\sqrt{2}\\left(|0\\rangle + |1\\rangle\\right)$, and $|-\\rangle = 1/\\sqrt{2}\\left(|0\\rangle - |1\\rangle\\right)$. \n",
    "\n",
    "Below is the code to create quantum circuits for performing experiments of $(2,1)$-QRAC. Each of the circuits consits of encoding $2$ bits of information into $1$ qubit and decoding either the first or the second bit by performing measurement on the qubit. Notice that because in the IBM Q Experience we can only perform measurement in the $\\left\\{|0\\rangle, |1\\rangle\\right\\}$ basis, the measurement in the $\\left\\{|+\\rangle, |-\\rangle\\right\\}$ basis is performed by first applying the Hadamard gate. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "List of circuit names: ['Encode00DecodeFirst', 'Encode00DecodeSecond', 'Encode01DecodeFirst', 'Encode01DecodeSecond', 'Encode10DecodeFirst', 'Encode10DecodeSecond', 'Encode11DecodeFirst', 'Encode11DecodeSecond']\n"
     ]
    }
   ],
   "source": [
    "backend = Aer.get_backend('qasm_simulator') # the device to run on\n",
    "shots = 1024    # the number of shots in the experiment \n",
    "\n",
    "#to record the rotation number for encoding 00, 10, 11, 01\n",
    "rotationNumbers = {\"00\":1, \"10\":3, \"11\":5, \"01\":7}\n",
    "\n",
    "# Creating registers\n",
    "# qubit for encoding 2 bits of information\n",
    "qr = QuantumRegister(1)\n",
    "# bit for recording the measurement of the qubit\n",
    "cr = ClassicalRegister(1)\n",
    "\n",
    "# dictionary for encoding circuits\n",
    "encodingCircuits = {}\n",
    "# Quantum circuits for encoding 00, 10, 11, 01\n",
    "for bits in (\"00\", \"01\", \"10\", \"11\"):\n",
    "    circuitName = \"Encode\"+bits\n",
    "    encodingCircuits[circuitName] = QuantumCircuit(qr, cr, name=circuitName)\n",
    "    encodingCircuits[circuitName].u3(rotationNumbers[bits]*pi/4.0, 0, 0, qr[0])\n",
    "    encodingCircuits[circuitName].barrier()\n",
    "\n",
    "# dictionary for decoding circuits\n",
    "decodingCircuits = {}\n",
    "# Quantum circuits for decoding the first and second bit\n",
    "for pos in (\"First\", \"Second\"):\n",
    "    circuitName = \"Decode\"+pos\n",
    "    decodingCircuits[circuitName] = QuantumCircuit(qr, cr, name=circuitName)\n",
    "    if pos == \"Second\": #if pos == \"First\" we can directly measure\n",
    "        decodingCircuits[circuitName].h(qr[0])\n",
    "    decodingCircuits[circuitName].measure(qr[0], cr[0])\n",
    "\n",
    "#combine encoding and decoding of QRACs to get a list of complete circuits\n",
    "circuitNames = []\n",
    "circuits = []\n",
    "for k1 in encodingCircuits.keys():\n",
    "    for k2 in decodingCircuits.keys():\n",
    "        circuitNames.append(k1+k2)\n",
    "        circuits.append(encodingCircuits[k1]+decodingCircuits[k2])\n",
    "\n",
    "print(\"List of circuit names:\", circuitNames) #list of circuit names"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, we can perform various experiments of $(2,1)$-QRAC. Below, we execute all circuits of QRACs and plot some experimental results. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Experimental Result of Encode01DecodeFirst\n",
      "Experimental Result of Encode01DecodeSecond\n",
      "Experimental Result of Encode11DecodeFirst\n",
      "Experimental Result of Encode11DecodeSecond\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAc0AAAEyCAYAAACYgYvRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAf2klEQVR4nO3de3SV9Z3v8fdXBAoULMEMJjIBEU4Ml4nx1upY1GOZ2noZa12ljlN1nOqx7dhaOmPbM62trcVVqh09tbbVcZbXzvFGx9qRqbW02orjBULKJc1BIzBIxAgMUECC8Xf+2BsbYxKejTvJhrxfa+2V/fye3/Pb3yd7hQ/PPVJKSJKkPTugvwuQJGlfYWhKkpSRoSlJUkaGpiRJGRmakiRlZGhKkpTRgf1dQH8aM2ZMqqqq6u8yJEklZMmSJa+mlMq7mjegQ7OqqooFCxb0dxmSpBJSVla2urt5fbp7NiJmRMRPI+KliEgRcVGGZaZHxOMRsSO/3FUREZ36fDQiVkTEzvzPj/TaSkiSBqy+Pqb5bmAZ8Dlgx546R8Qo4BfAeuDY/HL/AMzu0Od44F7gHuDI/M/7I+K9xS5ekjSw9enu2ZTSI8AjABFxe4ZFzgeGAxemlHYAyyLiCGB2RHw35e4BeAXwq5TSt/LLfCsiTsm3n1fsdZAkDVylfvbs8cBv8oG528+BSmBChz6Pdlru58AJvV6dJGlAKfXQPITcrtmO1neY11OfQ5AkqYgG3NmzEXEpcClARUUFixcvBqCyspLhw4fz/PPPA3DQQQcxceJE6uvrARg0aBC1tbU0NTWxbds2AGpqati4cSPr1+cye9y4cQwZMoTm5mYARo8eTVVVFQ0NDQAMHjyY6dOn09jYyI4duY3nKVOm0NraSmtrKwDjx48nIli1ahUAY8aMoaKigmXLlgEwdOhQpk6dyvLly9m5cycA06ZNo6WlhQ0bNgAwYcIEUkqsXp07Aay8vJzy8nJWrFgBwLBhw6ipqWHp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aZJSuhm4uZt5J/c03c0ynwc+X4zaJEnqifeelSQpI0NTkqSMDE1JkjIyNCVJysjQlCQpI0NTkqSMDE1JkjIyNCVJysjQlCQpI0NTkqSMDM0B7rHHHuO4447j6KOP5oYbbnjb/IULF3LyySdTXl7OQw899Lb5W7ZsYerUqVx55ZVvtrW1tXHFFVdw7LHH8t73vpef/vSnvboOktRX+vzesyod7e3tXHnllcybN4/KykpOPfVUTjvtNI444og3+4wbN47vf//73HTTTV2OMWfOHE444YS3tF1//fWUl5fz7LPP8sYbb7z5VHRJ2tcZmgPYokWLOOyww5gwYQIA55xzDvPnz39LaFZV5R48c8ABb98psWTJElpbWzn11FNZsmTJm+333HMPTz/99JvLjRkzphfXQpL6jrtnB7CWlhYOPfTQN6crKytpacn27O433niDr371q3zjG994S/vmzZuB3BboySefzEUXXcQrr7xSvKIlqR8Zmtort912GzNnznxL6AK8/vrrrFu3juOOO45f//rXHHvssVx11VX9VKUkFZe7ZwewiooKXnrppTen161bR0VFRaZln332WZ566iluu+02tm3bRltbGyNGjOCqq65i+PDhnHnmmQD85V/+JXfffXev1C9Jfc3QHMCOOuoompubWb16NRUVFcybN49bbrkl07Id+/34xz9myZIlfO1rXwPggx/8IL/97W+ZMWMGTzzxBNXV1b1SvyT1NXfPDmAHHnggc+fO5dxzz+V973sfZ599NjU1NcyZM4f58+cDsHjxYqZOncpDDz3E7NmzOf744/c47te//nW+/e1vc+KJJ3LfffdxzTXX9PaqSFKfiJRSf9fQb+rq6tKCBQv6uwxJfezKO0b3dwnqBXMvLM7lbWVlZYtSSsd0Nc8tTUmSMjI0JUnKyBOBisBdPfunYu3qkbT/cEtTkqSMDE1JkjIyNCVJysjQlCQpI0NTkqSMDE1JkjIyNCVJysjQlCQpI0NTkqSMDE1JkjIyNCVJysjQlCQpI0NTkqSMDE1JkjIyNCVJysjQlCQpI0NTkqSMDE1JkjIyNCVJysjQlCQpI0NTkqSMDE1JkjIyNCVJysjQlCQpI0NTkqSMDE1JkjIyNCV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L2EbuqTOtwAfInUn7yZTS0v6rUNJuETEaGJtS+n1EDAF2dTwhKCJmAf8KHOW5CHvP0NQe5S8/OR04G3iN3Bbm/Sml3/drYZJ6FBEHkPt3vj0iLiG3a3Z4f9e1LzM0VZCIOKDz8U1JpS8iZgODUkrf6e9a9mWGpiQNABExGGj3P73vjKEpSVJGnj0rSVJGhqYkSRkZmpIkZWRoSpKUkaEpSVJGhqYkSRn9f2e+l6GDnn1JAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job = execute(circuits, backend=backend, shots=shots)\n",
    "results = job.result()\n",
    "print(\"Experimental Result of Encode01DecodeFirst\")\n",
    "#We should measure \"0\" with probability 0.85\n",
    "plot_histogram(results.get_counts(circuits[circuitNames.index(\"Encode01DecodeFirst\")]))\n",
    "print(\"Experimental Result of Encode01DecodeSecond\")\n",
    "#We should measure \"1\" with probability 0.85\n",
    "plot_histogram(results.get_counts(circuits[circuitNames.index(\"Encode01DecodeSecond\")]))\n",
    "print(\"Experimental Result of Encode11DecodeFirst\")\n",
    "#We should measure \"1\" with probability 0.85\n",
    "plot_histogram(results.get_counts(circuits[circuitNames.index(\"Encode11DecodeFirst\")]))\n",
    "print(\"Experimental Result of Encode11DecodeSecond\")\n",
    "#We should measure \"1\" with probability 0.85\n",
    "plot_histogram(results.get_counts(circuits[circuitNames.index(\"Encode11DecodeSecond\")]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From the above simulations, we can see that each of the encoded bits can be decoded with probability closed to the theoretical values. We can now proceed to perform experiments on the real devices or local simulator, as below. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Job Status: job has successfully run\n"
     ]
    }
   ],
   "source": [
    "# Use the IBM Quantum Experience\n",
    "backend = least_busy(IBMQ.backends(simulator=False))\n",
    "job_exp = execute(circuits, backend=backend, shots=shots)\n",
    "job_monitor(job_exp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Experimental Result of Encode01DecodeFirst\n",
      "Experimental Result of Encode01DecodeSecond\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAcQAAAEyCAYAAABklKAbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAeHUlEQVR4nO3dfZSV5Xnv8e+V4SVAwTA4xUE6IMGwhhfpiGEJjVFjSIhNXZTa2BxPNW2tx3g0y6oxJz1pjmkasyQm0WM0MSatoj2tGPDYpuEElUai2NjASAWGKXYEikzoOBCgvDu5zh97Q4bJDMw2M3sc+H7W2mv2cz/3vefabDY/nvt5i8xEkqRT3dv6ugBJkt4KDERJkjAQJUkCDERJkgADUZIkwECUJAmAAX1dQG8ZNWpU1tTU9HUZkqS3kJdeeun1zKzqbN1JG4g1NTUsX768r8uQJL2FVFZWbu5qnVOmkiRhIEqSBBiIkiQBBqIkSYCBKEkSYCBKkgQYiJIkAQaiJEmAgShJEmAgSpIEGIiSJAEGoiRJgIEoSRJgIEqSBBiIkiQBBqIkSYCBKEkSYCBKkgQYiJIkAQaiJEmAgShJEmAgSpIEGIiS9Jbw9NNPM3PmTGbMmMHdd9/9C+u3bt3KZZddxoUXXsh73vMennrqqaPrvvrVrzJjxgxmzpzJM888c7T9/vvvZ9asWcyePZtrrrmGAwcOlOW99FcGoiT1sba2Nm677TYWLVrECy+8wOLFi9mwYcMxfe666y7mzZvHs88+y7e+9S1uvfVWADZs2MCSJUtYuXIljz/+OJ/85Cdpa2tj27ZtfPOb32T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ra2N2267jUWLFvHCCy+wePFiNmzYcEyfsWPHct9993H55Zcf075s2TLWrFnDihUreOqpp7jvvvvYvXs3AL/7u7/Lj370I55//nkOHDjAI488Urb3JEm9yUA8Sa1atYqzzjqL8ePHM2jQIObPn8/SpUuP6VNTU8OUKVN429uO/WuwYcMGZs+ezYABAxg2bBiTJ0/mmWeeAWDOnDlEBBHBueeey7Zt28r2niSpNxmIJ6nm5mbOPPPMo8tjxoyhubm5W2OnTp3KM888w759+2htbeW5557jtddeO6bP4cOHWbRoEZdcckmP1i1JfWVAXxegt573ve991NfXM3fuXEaNGsW73/1uKioqjulz6623MmvWLGbNmtVHVUpSz3IL8SRVXV19zFbdtm3bqK6u7vb4W265hRUrVvDEE0+QmUycOPHoujvvvJPW1la+8IUv9GjNktSXyh6IEXF9RLwaEQciYlVEXHCcvvMjYllEtETEnoj4UURcVs56+6tzzz2XpqYmNm/ezKFDh1iyZAlz587t1ti2tjZ27NgBwLp161i3bh0XX3wxAAsXLmT58uU8+OCDv7DvUZL6s7L+ixYRVwD3AHcAdcBKYGlE1HQx5EJgOfCbxf7fA544XoiqYMCAASxYsIDLL7+c888/n3nz5lFbW8sdd9xx9OCa1atXM2XKFJ588kluvvnmo9Ofhw8f5tJLL+X888/npptu4oEHHmDAgMLs+i233EJLSwsf/OAHee9738uCBQv67D1KUk+KzCzfL4v4EfAvmfnH7do2At/JzE938zVeBH6Ymbccr19dXV0uX778l6pXUv9z28Mj+7oE9YIFV+/skdeprKxclZnndbaubFuIETEImAEs67BqGTC7hJcaDvTMn4wkSUXlnDI9HagAtndo3w6c0Z0XiIj/DowFPBtcktSj+s1pFxHxO8CXgCsyc3MXfa4FroXCUZarV68GCufgDR06lFdeeQWA0047jQkTJlBfXw9ARUUF06dPp7Gxkb179wJQW1vLjh072L69kN9jx45l0KBBNDU1ATBy5EhqampYs2YNAAMHDmTatGk0NDSwf/9+ACZPnkxLSwstLS0AjBs3johg06ZNAIwaNYrq6mrWrl0LwODBg5kyZQrr1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SjetqRTkD8XWgDRjdoX008JMuxvyki/5v0Mlfgsz8JvDNX67MU1dE/Dgzz+vrOiR1j9/ZnlW2KdPMPASsAuZ0WDWHwlGknXmhi/4/zszDPVuhJOlUVu6jTL8CfCwiromI2oi4BxgDfAMgIhZGxMJ2/b8BnBkRdxf7XwN8DLirzHVLkk5yZd2HmJmPRcQo4DNANbAWuDQzNxe71HTo/2pEXAp8lcKpGduAT2Tm4jKWfSpxulnqX/zO9qDIzL6uQZKkPue1TCVJwkCUJAkwECVJAgzEU15EnB0RHc/1lKRTjgfVnIIi4leB3wf+BGihcKGDZuA7wOLM3NuH5UlSnzAQT0ER8RAwGfgu0AqMAn4dqAW2Agsy86k+K1DSL4iIEcCe9B/tXmMgnmIiIoA9FM7/XNGubSxwPvDHFK71d0VmvtRnhUo6RkQ8ALxYfGzOzN2d9BmVma1lL+4k4T7EU89k4FXg0JGGLPj3zHwc+DCFwLyij+qT1EFEfJTCf1a/DDwJfCkifjsi3hkRQ4p9hgDfjohpfVhqv+YW4imm+KX5LjAUuAr4t8z8WYc+NwJ/lJm/3gclSuogIh6kcHOEBcB84GrgnUAj8D3gGWAScE9mDuqrOvs7txBPMZm5H/ifwBBgIXBVRPxaRPwKQEQMBS6kcFk9SX0sIgZQmNX5aWY2ZeZdmTkNeDfwLIVwXATcCzzSd5X2f24hnqIiYirwZ8BlwF4KdxZpAd5P4YjTazLz5b6rUNIRETESGJ2ZGyJiEHC4/cE1EXEF8DfAue77f/MMxFNc8RSM3wTmAQcobBk+npkb+rQwSccVEW+j8G94W0T8MYXp0qF9XVd/ZiDqqIh4W8f9iZLe+iLiZqAiM7/U17X0ZwaiJPVzETEQaPM/tL8cA1GSJDzKVJIkwECUJAkwECVJAgxESZIAA1GSJMBAlCQJgP8P8IyarJZVj1kAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results = job_exp.result()\n",
    "print(\"Experimental Result of Encode01DecodeFirst\")\n",
    "#We should measure \"0\" with probability 0.85\n",
    "plot_histogram(results.get_counts(circuits[circuitNames.index(\"Encode01DecodeFirst\")]))\n",
    "print(\"Experimental Result of Encode01DecodeSecond\")\n",
    "#We should measure \"1\" with probability 0.85\n",
    "plot_histogram(results.get_counts(circuits[circuitNames.index(\"Encode01DecodeSecond\")]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Encoding 3 bits into 1 qubit with $(3,1)$-QRAC\n",
    "We follow Example 2 described in the paper [here](http://iopscience.iop.org/article/10.1088/1367-2630/8/8/129/meta). \n",
    "Alice encodes her $3$ bits $x_1x_2x_3$ by preparing the following 1-qubit states $|\\phi_{x_1x_2x_3}\\rangle$ as below, where $\\cos^2\\left(\\theta\\right) = 1/2 + \\sqrt{3}/6 > 0.788$.   \n",
    "\n",
    "\\begin{eqnarray}\n",
    "|\\phi_{000}\\rangle &=& \\cos\\left(\\theta\\right)|0\\rangle + e^{i\\pi/4}\\sin\\left(\\theta\\right)|1\\rangle\\\\\n",
    "|\\phi_{001}\\rangle &=& \\cos\\left(\\theta\\right)|0\\rangle + e^{-i\\pi/4}\\sin\\left(\\theta\\right)|1\\rangle\\\\\n",
    "|\\phi_{010}\\rangle &=& \\cos\\left(\\theta\\right)|0\\rangle + e^{3i\\pi/4}\\sin\\left(\\theta\\right)|1\\rangle\\\\\n",
    "|\\phi_{011}\\rangle &=& \\cos\\left(\\theta\\right)|0\\rangle + e^{-3i\\pi/4}\\sin\\left(\\theta\\right)|1\\rangle\\\\\n",
    "|\\phi_{100}\\rangle &=& \\sin\\left(\\theta\\right)|0\\rangle + e^{i\\pi/4}\\cos\\left(\\theta\\right)|1\\rangle\\\\\n",
    "|\\phi_{101}\\rangle &=& \\sin\\left(\\theta\\right)|0\\rangle + e^{-i\\pi/4}\\cos\\left(\\theta\\right)|1\\rangle\\\\\n",
    "|\\phi_{110}\\rangle &=& \\sin\\left(\\theta\\right)|0\\rangle + e^{3i\\pi/4}\\cos\\left(\\theta\\right)|1\\rangle\\\\\n",
    "|\\phi_{111}\\rangle &=& \\sin\\left(\\theta\\right)|0\\rangle + e^{-i\\pi/4}\\cos\\left(\\theta\\right)|1\\rangle\\\\\n",
    "\\end{eqnarray}\n",
    "\n",
    "Bob recovers his choice of bit by measuring the qubit similarly as in the $(2,1,0.85)$-QRAC for the first and second bit, and to recover the third bit, he measures the qubit in the $\\left\\{|+'\\rangle, |-'\\rangle\\right\\}$ basis, where $|+'\\rangle = 1/\\sqrt{2}\\left(|0\\rangle + i |1\\rangle\\right)$, and $|-'\\rangle = 1/\\sqrt{2}\\left(|0\\rangle - i |1\\rangle\\right)$. \n",
    "\n",
    "Intuitively, the encoding of $(3,1)$-QRAC correspond to assigning the $8$ states to the corners of the unit cube inside the Bloch Sphere as depicted in the figure below. \n",
    "<img src=\"../../images/blochsphere31.png\" alt=\"Note: In order for images to show up in this jupyter notebook you need to select File => Trusted Notebook\" width=\"300 px\" align=\"center\">\n",
    "\n",
    "Below is the code to create quantum circuits for performing experiments of $(3,1)$-QRAC. Similarly to the $(2,1)$-QRAC, each of the circuits consists of encoding $3$ bits of information into $1$ qubit and decoding either the first, the second, or the third bit by performing measurement on the qubit."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "List of circuit names: ['Encode000DecodeFirst', 'Encode000DecodeSecond', 'Encode000DecodeThird', 'Encode010DecodeFirst', 'Encode010DecodeSecond', 'Encode010DecodeThird', 'Encode100DecodeFirst', 'Encode100DecodeSecond', 'Encode100DecodeThird', 'Encode110DecodeFirst', 'Encode110DecodeSecond', 'Encode110DecodeThird', 'Encode001DecodeFirst', 'Encode001DecodeSecond', 'Encode001DecodeThird', 'Encode011DecodeFirst', 'Encode011DecodeSecond', 'Encode011DecodeThird', 'Encode101DecodeFirst', 'Encode101DecodeSecond', 'Encode101DecodeThird', 'Encode111DecodeFirst', 'Encode111DecodeSecond', 'Encode111DecodeThird']\n"
     ]
    }
   ],
   "source": [
    "backend = Aer.get_backend('qasm_simulator') # the device to run on\n",
    "shots = 1024    # the number of shots in the experiment \n",
    "from math import sqrt, cos, acos\n",
    "\n",
    "#compute the value of theta\n",
    "theta = acos(sqrt(0.5 + sqrt(3.0)/6.0))\n",
    "\n",
    "#to record the u3 parameters for encoding 000, 010, 100, 110, 001, 011, 101, 111\n",
    "rotationParams = {\"000\":(2*theta, pi/4, -pi/4), \"010\":(2*theta, 3*pi/4, -3*pi/4), \n",
    "                  \"100\":(pi-2*theta, pi/4, -pi/4), \"110\":(pi-2*theta, 3*pi/4, -3*pi/4), \n",
    "                  \"001\":(2*theta, -pi/4, pi/4), \"011\":(2*theta, -3*pi/4, 3*pi/4), \n",
    "                  \"101\":(pi-2*theta, -pi/4, pi/4), \"111\":(pi-2*theta, -3*pi/4, 3*pi/4)}\n",
    "\n",
    "# Creating registers\n",
    "# qubit for encoding 3 bits of information\n",
    "qr = QuantumRegister(1)\n",
    "# bit for recording the measurement of the qubit\n",
    "cr = ClassicalRegister(1)\n",
    "\n",
    "# dictionary for encoding circuits\n",
    "encodingCircuits = {}\n",
    "# Quantum circuits for encoding 000, ..., 111\n",
    "for bits in rotationParams.keys():\n",
    "    circuitName = \"Encode\"+bits\n",
    "    encodingCircuits[circuitName] = QuantumCircuit(qr, cr, name=circuitName)\n",
    "    encodingCircuits[circuitName].u3(*rotationParams[bits], qr[0])\n",
    "    encodingCircuits[circuitName].barrier()\n",
    "\n",
    "# dictionary for decoding circuits\n",
    "decodingCircuits = {}\n",
    "# Quantum circuits for decoding the first, second and third bit\n",
    "for pos in (\"First\", \"Second\", \"Third\"):\n",
    "    circuitName = \"Decode\"+pos\n",
    "    decodingCircuits[circuitName] = QuantumCircuit(qr, cr, name=circuitName)\n",
    "    if pos == \"Second\": #if pos == \"First\" we can directly measure\n",
    "        decodingCircuits[circuitName].h(qr[0])\n",
    "    elif pos == \"Third\":\n",
    "        decodingCircuits[circuitName].u3(pi/2, -pi/2, pi/2, qr[0])\n",
    "    decodingCircuits[circuitName].measure(qr[0], cr[0])\n",
    "\n",
    "#combine encoding and decoding of QRACs to get a list of complete circuits\n",
    "circuitNames = []\n",
    "circuits = []\n",
    "for k1 in encodingCircuits.keys():\n",
    "    for k2 in decodingCircuits.keys():\n",
    "        circuitNames.append(k1+k2)\n",
    "        circuits.append(encodingCircuits[k1]+decodingCircuits[k2])\n",
    "\n",
    "print(\"List of circuit names:\", circuitNames) #list of circuit names"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, we can perform various experiments of $(3,1)$-QRAC. Below, we execute all circuits of QRACs and plot some experimental results. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Experimental Result of Encode010DecodeFirst\n",
      "Experimental Result of Encode010DecodeSecond\n",
      "Experimental Result of Encode010DecodeThird\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAcQAAAEyCAYAAABklKAbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAeNUlEQVR4nO3de5iV5Xnv8e8tJ8GiMjjFQQKIkOlwCB1QtxpFW8VoTK0lNti4q0mbutUds1uTbZtoY2y77RUTE9xGTUJtPdVUjWhaozvUkkajNrYwQQ4Tgh0BkZEOhwAFZMj03n+sBRmGGZilM2sJ8/1c17pmred9npl7ZWX54z08zxuZiSRJfd0RlS5AkqR3AwNRkiQMREmSAANRkiTAQJQkCTAQJUkCoH+lC+gtw4cPz9GjR1e6DEnSu8iPf/zjDZlZ3dm2wzYQR48ezYIFCypdhiTpXaSq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UR/Ckd1fpaZTZn55cycApwC/IBCOD4K3Ak8WLlKD33uIfZRETEZ+FPgYmA7hTuLtADnUbji9BOZuaRyFUraIyKGASMy8ycRMRDY3f7imoiYDXwLmOa5/7fPQOzjilMwLgIuAd6isGf4WGb+pKKFSTqgiDiCwn/D2yLiDygcLh1S6boOZQai9oqIIzqeT5T07hcR1wP9MvNLla7lUGYgStIhLiIGAG3+g/adMRAlScKrTCVJAgxESZIAA1GSJMBAlCQJMBAlSQIMREmSAPj/jLl0lES4glcAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job = execute(circuits, backend=backend, shots=shots)\n",
    "results = job.result()\n",
    "print(\"Experimental Result of Encode010DecodeFirst\")\n",
    "# We should measure \"0\" with probability 0.78\n",
    "plot_histogram(results.get_counts(circuits[circuitNames.index(\"Encode010DecodeFirst\")]))\n",
    "print(\"Experimental Result of Encode010DecodeSecond\")\n",
    "# We should measure \"1\" with probability 0.78\n",
    "plot_histogram(results.get_counts(circuits[circuitNames.index(\"Encode010DecodeSecond\")]))\n",
    "print(\"Experimental Result of Encode010DecodeThird\")\n",
    "# We should measure \"0\" with probability 0.78\n",
    "plot_histogram(results.get_counts(circuits[circuitNames.index(\"Encode010DecodeThird\")]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, we can perform various experiments of $(3,1)$-QRAC. Below, we execute all circuits of QRACs and plot some experimental results. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Job Status: job has successfully run\n"
     ]
    }
   ],
   "source": [
    "# Use the IBM Quantum Experience\n",
    "backend = least_busy(IBMQ.backends(simulator=False))\n",
    "job_exp = execute(circuits, backend=backend, shots=shots)\n",
    "job_monitor(job_exp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Experimental Result of Encode010DecodeFirst\n",
      "Experimental Result of Encode010DecodeSecond\n",
      "Experimental Result of Encode010DecodeThird\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAcQAAAEyCAYAAABklKAbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAeKElEQVR4nO3dfXSV5Znv8e8lEAoWKUGKiUxAhEnDizRqfWkVdKmt1VMXg646PY7adjoetaM9w5nasadV65zjrGVrB8dTj63T1rdxRltpZ2rrkVpmtLZMnUGKojFiIyCQ0giIFJBgep0/9obGmEC2JnsT8v2stVf2cz/3k31tt5tf7uflfiIzkSRpsDuo0gVIkrQ/MBAlScJAlCQJMBAlSQIMREmSAANRkiQAhla6gP4yduzYrKurq3QZkqT9yC9/+cuXM3Ncd+sO2ECsq6tj8eLFlS5DkrQfqa6uXt3TOneZSpKEgShJEmAgSpIEGIiSJAEGoiRJgIEoSRJgIEqSBBiIkiQBBqIkSYCBKEkSYCBKkgQYiJIkAQaiJEmAgShJEmAgSpIEGIiSJAEGoiRJgIEoSRJgIEqSBBiIkiQBBqIkSYCBKEkSYCAe0B555BGOO+44jjnmGBYsWPCm9Z///OeZPXs2s2fP5n3vex+TJk3as27t2rXMmzeP448/nhNOOIE1a9YAcPvtt3PMMcdQXV3Nxo0by/VWJKnfDa10AeofHR0dXHXVVSxcuJDa2lpOO+00zjzzTN7znvfs6XPDDTfsef6Nb3yDp556as/yZZddxvz58zn11FP57W9/y0EHFf52Ov744/nQhz7ERz7ykfK9GUkqA0eIB6ilS5dyxBFHMGnSJKqqqpg3bx4PPfRQj/0feOABzj33XACee+45Xn/9dU499VQA3vnOdzJy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N39W2FkqTBrNxnmX4V+HhEfCoiGiLiZqAWuA0gIu6KiLs69b8NODwiFhT7fwr4OPCVMtctSTrAlfUYYmbeFxFjgS8ANcAK4KzMXF3sUtel/4sRcRbwtxQuzVgPXJmZD5Sx7MHE3c3SwOJ3tg9FZla6BkmSKs65TCVJwkCUJAkwECVJAgzEQS8ipkZE12s9JWnQ8aSaQSgi3g1cCPwF0EZhooNW4LvAA5m5rYLlSVJFGIiDUETcAUwDHgQ2AmOB9wINwFrgxsz8ccUKlPQmEXEIsDX9R7vfGIiDTEQEsJXC9Z+PdWqbAJwA/BmFuf7Oz8xfVqxQSW8QEV8Hnig+Vmfmq930GZuZG8te3AHCY4iDzzTgRaB9d0MWvJSZ3wH+C4XAPL9C9UnqIiI+RuGP1ZuAfwa+HBF/FBFHRsSIYp8RwDcjYmYFSx3QHCEOMsUvzYPASOAi4FeZ+bsufa4A/jQz31uBEiV1ERG3U7g5wo3APOBi4EigGfgR8BOgHrg5M6sqVedA5whxkMnMHcD/BEYAdwEXRcQfRMQ7ASJiJDCHwrR6kiosIoZS2KvzSma2ZOZXMnMm8D7gUQrheD9wC3B35Sod+BwhDlIRMQP4InAOsI3CnUXagNMpnHH6qcx8unIVStotIsYA4zPzuYioAnZ1PrkmIs4H/hE42mP/b52BOMgVL8E4G5gLvEZhZPidzHyuooVJ2quIOIjCv+EdEfFnFHaXjqx0XQOZgag9IuKgrscTJe3/ImI+MCQzv1zpWgYyA1GSBriIGAZ0+Aft22MgSpKEZ5lKkgQYiJIkAQaiJEmAgShJEmAgSpIEGIiSJAHw/wHXL1/5RzPqkQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results = job_exp.result()\n",
    "print(\"Experimental Result of Encode010DecodeFirst\")\n",
    "plot_histogram(results.get_counts(circuits[circuitNames.index(\"Encode010DecodeFirst\")]))\n",
    "#We should measure \"0\" with probability 0.78\n",
    "print(\"Experimental Result of Encode010DecodeSecond\")\n",
    "#We should measure \"1\" with probability 0.78\n",
    "plot_histogram(results.get_counts(circuits[circuitNames.index(\"Encode010DecodeSecond\")]))\n",
    "print(\"Experimental Result of Encode010DecodeThird\")\n",
    "#We should measure \"0\" with probability 0.78\n",
    "plot_histogram(results.get_counts(circuits[circuitNames.index(\"Encode010DecodeThird\")]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## About Quantum Random Access Coding\n",
    "The notion of Quantum RAC was first presented [here](https://arxiv.org/abs/quant-ph/9804043) along with the concrete example of $(2,1)$-QRAC which apparently was discovered much earlier in 1983 by [Wiesner](http://dl.acm.org/citation.cfm?doid=1008908.1008920). The idea of the $(3,1)$-QRAC appeared in the [classic book of Mike and Ike](https://www.amazon.com/Quantum-Computation-Information-10th-Anniversary/dp/1107002176). The first experiments on $(2,1)$-QRAC and $(3,1)$-QRAC were presented [here](https://arxiv.org/abs/0805.1463). It is not possible to perform $(4,1)$-QRAC as shown [here](http://iopscience.iop.org/article/10.1088/1367-2630/8/8/129/meta).  "
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
